<template>
  <div id="flight-refund-order-detail">
    <nav aria-label="breadcrumb" role="navigation">
      <ol class="breadcrumb">
        <li class="breadcrumb-item">
          <router-link to="/flt/change/orders">改签单</router-link>
        </li>
        <li class="breadcrumb-item active" aria-current="page">详情</li>
        <span class="ms-auto" @click.stop="back()">返回</span>
      </ol>
    </nav>
    <template v-if="detail !== null">
      <ul class="nav nav-tabs nav-bordered mb-3" id="myTab" role="tablist">
        <li class="nav-item">
          <a
            class="nav-link active"
            id="order-tab"
            data-bs-toggle="tab"
            href="#orderDetailTab"
            role="tab"
            aria-controls="home"
            aria-selected="true"
            >改签单信息</a
          >
        </li>
        <li
          class="nav-item"
          v-if="detail !== null && detail.smsDetails.length > 0"
        >
          <a
            class="nav-link"
            id="sms-tab"
            data-bs-toggle="tab"
            href="#smsDetailTab"
            role="tab"
            aria-controls="sms"
            aria-selected="false"
            >短信({{ detail.smsDetails.length }})</a
          >
        </li>
      </ul>
      <div class="tab-content" id="myTabContent">
        <div
          class="tab-pane fade show active"
          id="orderDetailTab"
          role="tabpanel"
          aria-labelledby="order-tab"
        >
          <div class="card">
            <table class="table table-sm table-striped">
              <thead>
                <tr>
                  <th>改签单号</th>
                  <th class="text-center">票号</th>
                  <th>乘客</th>
                  <th class="text-center">证件号</th>
                  <th>原编码</th>
                  <th>新票号</th>
                  <th>新编码</th>

                  <th class="text-end">销售价</th>
                  <th class="text-end">税</th>
                  <th class="text-end">航司改签费</th>
                  <th class="text-end">我司服务费</th>
                  <th>状态</th>
                  <th>提交时间</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>{{ detail.changeOrderNo }}</td>
                  <td class="text-center">
                    {{ detail.balanceCode }}-{{ detail.ticketNo }}
                  </td>
                  <td>
                    {{ detail.psgName }}
                    <span v-if="detail.mobile !== null">{{
                      detail.mobile
                    }}</span>
                  </td>
                  <td class="text-center">{{ detail.idNo }}</td>
                  <td>{{ detail.oldPnrNo }}</td>

                  <td>{{ detail.newTicketNo }}</td>
                  <td>{{ detail.newPnrNo }}</td>

                  <td class="text-end">{{ detail.parValue }}</td>
                  <td class="text-end">{{ detail.tax }}</td>
                  <td class="text-end">{{ detail.airChangeCharge }}</td>
                  <td class="text-end">{{ detail.serviceCharge }}</td>

                  <td>
                    {{ getStatus(detail.status) }}
                    <span
                      class="small text-primary"
                      v-if="detail.payStatus === 2"
                      >已销</span
                    >
                  </td>
                  <td>{{ detail.createTime }}</td>
                </tr>
              </tbody>
            </table>
            <table class="table table-striped table-hover table-sm">
              <thead>
                <tr>
                  <th>公司名称</th>
                  <th>原订单号</th>
                  <th>国际?</th>
                  <th>付款方式</th>
                  <th>付款备注</th>
                  <th>供应商</th>
                  <th>支付方式</th>
                  <th>操作员</th>
                  <th>处理人</th>
                  <th>修改时间</th>
                  <th>备注</th>
                  <th>外部订单号</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>
                    {{ detail.customer.name }}
                    <!--  -->
                  </td>
                  <td>
                    <router-link :to="`/flt/order/0?orderNo=` + detail.orderNo">
                      {{ detail.orderNo }}</router-link
                    >
                    <span
                      class="small"
                      v-if="
                        detail.parentChangeOrderNo !== null &&
                        detail.parentChangeOrderNo.length > 0
                      "
                    >
                      ({{ detail.parentChangeOrderNo }})
                    </span>
                  </td>
                  <td>
                    <span class="text-danger" v-if="detail.intlTicket === 1"
                      >国际</span
                    >
                    <span v-else>国内</span>
                  </td>

                  <td>{{ showPayType(detail.payType) }}</td>
                  <td>{{ detail.payRemark }}</td>
                  <td>
                    <template v-if="detail.supplier !== null">
                      {{ detail.supplier.name }}
                    </template>
                  </td>
                  <td>
                    <template v-if="detail.paymentMethod !== null">
                      {{ detail.paymentMethod.name }}
                    </template>
                  </td>
                  <td>{{ detail.operator }}</td>
                  <td>{{ detail.ticketer }}</td>
                  <td>{{ detail.lastUpdate }}</td>
                  <td>
                    {{ detail.remark }}
                    <template v-if="detail.status !== 2 && detail.status !== 4">
                      <a
                        href="javascript:void(0)"
                        @click.stop="editRemark()"
                        class="small ms-2"
                        title="修改备注"
                        >修改</a
                      >
                    </template>
                  </td>
                  <td>{{ detail.externalOrderNo }}</td>
                </tr>
              </tbody>
            </table>

            <template
              v-if="isAdmin && detail.status !== 4 && detail.status !== 32"
            >
              <div class="card-body bg-primary text-white py-1">
                南航NDC操作区
              </div>
              <div class="card-body">
                <button
                  type="button"
                  class="btn btn-primary btn-sm ms-3"
                  @click="createOrderChange($event.target)"
                >
                  提交改签单
                </button>
                <button
                  type="button"
                  class="btn btn-secondary btn-sm ms-3"
                  @click.stop="syncExternalOrderStatus($event.target)"
                >
                  同步改签单
                </button>
                <button
                  type="button"
                  class="btn btn-primary btn-sm ms-3"
                  @click.stop="payForExternalOrder()"
                >
                  支付
                </button>
              </div>
            </template>

            <div class="card-body bg-info text-white py-0">航班信息</div>
            <table class="table table-striped table-hover table-sm">
              <thead>
                <tr>
                  <th>出发</th>
                  <th>到达</th>
                  <th>航班号</th>
                  <th>舱位</th>
                  <th>出发日期</th>
                  <th>出发时间</th>
                  <th>到达时间</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(info, index) in detail.flights" :key="index">
                  <td>
                    <span v-if="info.fltType === 1" class="text-success"
                      >新:</span
                    >
                    <span v-if="info.fltType === 0" class="text-danger"
                      >原:</span
                    >
                    {{ info.dportName }}
                    <small>{{ info.dport }} {{ info.dterm }}</small>
                  </td>
                  <td>
                    {{ info.aportName }}
                    <small>{{ info.aport }} {{ info.aterm }}</small>
                  </td>
                  <td>{{ info.flightNo }}</td>
                  <td>{{ info.subclass }}</td>
                  <td>{{ info.ddate }}</td>
                  <td>{{ info.dtime }}</td>
                  <td>{{ info.atime }}</td>
                  <td>
                    <button
                      type="button"
                      class="btn btn-sm btn-secondary"
                      v-if="
                        info.fltType === 1 &&
                        (detail.status === 0 || detail.status === 1)
                      "
                      @click.stop="updateFlightInfo(info)"
                    >
                      修改
                    </button>
                  </td>
                </tr>
              </tbody>
            </table>
            <template v-if="detail.detrFlights.length > 0">
              <div class="card-body bg-info text-white py-0">DETR信息</div>
              <table class="table table-hover table-sm">
                <thead class="table-light">
                  <tr>
                    <th>出发</th>
                    <th>到达</th>
                    <th>航班号</th>
                    <th>舱位</th>
                    <th>出发日期</th>
                    <th>出发时间</th>
                    <th></th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="(info, index) in detail.detrFlights" :key="index">
                    <td>
                      <span v-if="info.fltType === 1" class="text-success"
                        >新:</span
                      >
                      <span v-if="info.fltType === 0" class="text-danger"
                        >原:</span
                      >
                      {{ info.dportName }}
                      <small>{{ info.dport }} {{ info.dterm }}</small>
                    </td>
                    <td>
                      {{ info.aportName }}
                      <small>{{ info.aport }} {{ info.aterm }}</small>
                    </td>
                    <td>{{ info.flightNo }}</td>
                    <td>{{ info.subclass }}</td>
                    <td>{{ info.ddate }}</td>
                    <td>{{ info.dtime }}</td>
                    <td>
                      {{ info.ticketStatus }}
                    </td>
                  </tr>
                </tbody>
              </table>
            </template>

            <div
              class="card-body bg-info text-white py-0"
              v-if="detail.attachments.length > 0"
            >
              附件
            </div>
            <table
              class="table table-striped table-sm table-hover"
              v-if="detail.attachments.length > 0"
            >
              <caption>
                已有的附件
              </caption>
              <thead>
                <tr>
                  <th>文件名</th>
                  <th>类型</th>
                  <th>尺寸</th>
                  <th>描述</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="info of detail.attachments">
                  <td>{{ info.fileName }}</td>
                  <td>{{ info.contentType }}</td>
                  <td>{{ info.fileSize }}</td>
                  <td>
                    {{ info.description }}
                  </td>
                  <td>
                    <template v-if="info.contentType.indexOf('image') >= 0">
                      <img
                        :src="info.url"
                        style="width: 2em; height: 2em"
                        @click.stop="viewImg(info.url)"
                      />
                    </template>
                    <a :href="info.url">下载</a>
                  </td>
                </tr>
              </tbody>
            </table>

            <div class="card-footer d-flex flex-row justify-content-around">
              <template v-if="detail.status === 0">
                <button
                  class="btn btn-warning btn-sm me-2"
                  @click.stop="updateTicketNo()"
                  v-if="isAdmin"
                >
                  修改票号
                </button>
                <button
                  class="btn btn-danger btn-sm me-auto"
                  @click.stop="cancelChange(detail.id)"
                >
                  取消
                </button>
                <button
                  class="btn btn-sm btn-primary"
                  @click.stop="processChange(detail.id)"
                >
                  我来处理
                </button>
              </template>
              <template v-else-if="detail.status === 1">
                <button
                  class="btn btn-danger btn-sm me-auto"
                  @click.stop="cancelChange(detail.id)"
                >
                  取消
                </button>
                <button
                  class="btn btn-info btn-sm ms-auto me-auto"
                  @click.stop="editPrice()"
                >
                  修改价格
                </button>
                <button
                  class="btn btn-info btn-sm ms-auto me-auto"
                  @click.stop="editTicketSupplier()"
                >
                  更改供应商
                </button>
                <button
                  class="btn btn-info btn-sm ms-auto me-auto"
                  @click.stop="editTicketPayment()"
                >
                  更改支付方式
                </button>
                <button
                  class="btn btn-success btn-sm ms-auto me-auto"
                  @click.stop="finishChangeOrder(detail.id)"
                >
                  处理完毕
                </button>
              </template>
              <template
                class="d-flex flex-row justify-content-around"
                v-else-if="detail.status === 4"
              >
                <button
                  class="btn btn-danger btn-sm ms-2"
                  @click.stop="reopenChange(detail.id)"
                  v-if="isAdmin"
                >
                  重新打开
                </button>
              </template>

              <template
                class="d-flex flex-row justify-content-around"
                v-if="detail.status === 2"
              >
                <button
                  class="btn btn-danger btn-sm ms-2"
                  @click.stop="rollbackStatus()"
                  v-if="isAdmin && detail.payStatus !== 2"
                >
                  回滚
                </button>
                <template v-if="detail.detrRefreshStatus !== 8">
                  <button
                    class="btn btn-warning ms-auto me-auto"
                    @click.stop="changeTicket()"
                  >
                    改签
                  </button>
                  <button
                    class="btn btn-danger ms-auto me-auto"
                    @click.stop="refundTicket()"
                    v-if="detail.newTicketNo.length === 14"
                  >
                    退票
                  </button>
                </template>
                <button
                  class="btn btn-info btn-sm ms-auto me-auto"
                  @click.stop="sendSms()"
                >
                  短信
                </button>

                <button
                  class="btn btn-secondary btn-sm ms-auto me-3"
                  @click.stop="editAttachment()"
                >
                  添加附件
                </button>

                <template v-if="detail.status === 2">
                  <button
                    class="btn btn-success btn-sm ms-auto me-auto"
                    @click.stop="outputBillInfo()"
                  >
                    输出为账单
                  </button>
                </template>

                
              </template>

              <button
                  type="button"
                  class="btn btn-info btn-sm float-end ms-5"
                  @click.stop="searchHistories()"
                >
                  查看操作记录
                </button>
            </div>
          </div>
          <div class="card">
            <table class="table table-sm table-striped">
              <thead>
                <tr>
                  <th>时间</th>
                  <th>内容</th>
                  <th>操作人</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="info in histories" :key="info.id">
                  <td>{{ info.createTime }}</td>
                  <td>{{ info.content }}</td>
                  <td>{{ info.operator }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
        <div
          class="tab-pane fade"
          id="smsDetailTab"
          role="tabpanel"
          aria-labelledby="sms-tab"
          v-if="detail !== null && detail.smsDetails.length > 0"
        >
          <sms-detail-list :dataList="detail.smsDetails"></sms-detail-list>
        </div>
      </div>
    </template>

    <my-modal-prompt ref="modalPrompt" :nullable="modalNullable">
      <span slot="title">{{ modalTitle }}</span>
    </my-modal-prompt>
    <my-modal-change-ticket-finished ref="modalFinishChange">
      <span slot="title">{{ modalTitle }}</span>
    </my-modal-change-ticket-finished>
    <my-modal-supplier-update
      ref="updateSupplierModal"
    ></my-modal-supplier-update>
    <my-modal-pay-method-update
      ref="updatePayMethodModal"
    ></my-modal-pay-method-update>
    <my-modal-price-update ref="updateChangeOrderPriceModal">
      <span slot="title">{{ modalTitle }}</span>
      <span slot="price1Title">{{ price1Title }}</span>
      <span slot="price2Title">{{ price2Title }}</span>
    </my-modal-price-update>
    <my-modal-change-ticket ref="changeTicketModal"></my-modal-change-ticket>
    <my-modal-refund-ticket ref="refundTicketModal"></my-modal-refund-ticket>
    <my-modal-flight-update ref="modalFlightUpdate"></my-modal-flight-update>
    <my-modal-sms ref="modalSms" :orderType="orderType">
      <span slot="title">{{ modalTitle }}</span>
    </my-modal-sms>
    <my-modal-viewer ref="modalViewer"></my-modal-viewer>
    <my-modal-upload-attachment
      ref="modalUploadFile"
      :orderType="orderType"
      :orderId="id"
    >
    </my-modal-upload-attachment>
  </div>
</template>

<script>
import {
  processChangeOrder,
  finishChangeOrder,
  cancelChangeOrder,
  reopenChangeOrder,
  updateChangeOrderSupplier,
  updateChangeOrderPayment,
  updateChangeOrderRemark,
  updateChangeOrderPrice,
  updateChangeOrderFlightInfo,
  updateChangeOrderTicketNo,
  searchChangeOrderDetail,
  searchChangeOrderHistory,
  showChangeOrderStatus,
  outputFlightChangeOrder2Bill,
  createChangeOrder,
  createExternalOrderChange,
  syncExternalOrderChangeStatus,
  payForExternalOrder,
} from "@/api/flight-change.js";

import { createRefundOrder } from "@/api/flight-refund.js";
import { showPayType } from "@/common/common.js";
import { ORDER_TYPE_FLIGHT_CHANGE } from "@/common/const.js";
import { sendOrderSmsContent } from "@/api/sms.js";
import { rollbackChangeOrderStatus } from "@/api/admin.js";
import MyModalChangeTicketFinished from "@/components/modal/my-modal-change-ticket-finished.vue";
import MyModalSupplierUpdate from "@/components/modal/my-modal-supplier-update.vue";
import MyModalPayMethodUpdate from "@/components/modal/my-modal-pay-method-update.vue";
import MyModalPrompt from "@/components/modal/my-modal-prompt.vue";
import MyModalPriceUpdate from "@/components/modal/my-modal-price-update.vue";
import MyModalChangeTicket from "@/components/modal/my-modal-change-ticket.vue";
import MyModalRefundTicket from "@/components/modal/my-modal-refund-ticket.vue";
import MyModalFlightUpdate from "@/components/modal/my-modal-flight-update.vue";
import MyModalSms from "@/components/modal/my-modal-sms.vue";
import MyModalViewer from "@/components/modal/my-modal-viewer.vue";
import MyModalUploadAttachment from "@/components/modal/my-modal-upload-attatchment.vue";
import SmsDetailList from "@/components/list/sms-detail-list.vue";
import OrderAttachments from "@/components/attachment/order-attachments.vue";

export default {
  components: {
    MyModalChangeTicketFinished,
    MyModalSupplierUpdate,
    MyModalPayMethodUpdate,
    MyModalPrompt,
    MyModalPriceUpdate,
    MyModalChangeTicket,
    MyModalRefundTicket,
    MyModalFlightUpdate,
    MyModalSms,
    MyModalViewer,
    MyModalUploadAttachment,
    SmsDetailList,
    OrderAttachments,
  },
  data() {
    return {
      detail: null,
      id: 0,
      histories: [],

      modalTitle: "",
      modalNullable: true,
      price1Title: "",
      price2Title: "",
    };
  },
  computed: {
    isAdmin() {
      return this.$store.getters.isAdmin;
    },
    orderType() {
      return ORDER_TYPE_FLIGHT_CHANGE;
    },
  },
  mounted: function () {
    this.id = parseInt(this.$route.params.id);
    this.search();
  },
  methods: {
    back: function () {
      this.$router.go(-1);
    },
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    search: function () {
      searchChangeOrderDetail(this.id, (val) => {
        this.detail = val;
      });
    },
    searchHistories: function () {
      searchChangeOrderHistory(this.id, (v) => {
        this.histories = v;
      });
    },
    getStatus: function (val) {
      return showChangeOrderStatus(val);
    },
    outputBillInfo: function () {
      outputFlightChangeOrder2Bill(this.id, (v) => this.commonShowMessage(v));
    },
    processChange: function (id) {
      processChangeOrder(id, (v) => this.commonShowMessage(v));
    },
    cancelChange: function (id) {
      this.modalTitle = "确定取消改签单吗？";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal()
        .then((remark) => {
          cancelChangeOrder(id, { remark: remark }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    reopenChange: function (id) {
      this.modalTitle = "确定重开改签单吗？";
      this.$refs.modalPrompt
        .modal("YesOrNo")
        .then((remark) => {
          reopenChangeOrder(id, (v) => this.commonShowMessage(v));
        })
        .catch((ex) => {});
    },
    finishChangeOrder: function (id) {
      this.$refs.modalFinishChange
        .modal()
        .then((info) => {
          finishChangeOrder(id, info, (v) => this.commonShowMessage(v));
        })
        .catch((ex) => {});
    },
    editTicketSupplier: function () {
      const promise = this.$refs.updateSupplierModal.modal(this.supplierId);
      promise
        .then((info) => {
          updateChangeOrderSupplier(
            this.id,
            { supplierId: info.supplierId },
            (v) => this.commonShowMessage(v)
          );
        })
        .catch(() => {});
    },
    editTicketPayment: function () {
      this.$refs.updatePayMethodModal
        .modal(this.payMethodId)
        .then((info) => {
          updateChangeOrderPayment(
            this.id,
            { paymentMethodId: info.payMethodId },
            (v) => this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    editRemark: function () {
      this.modalTitle = "请输入新的备注：";
      const promise = this.$refs.modalPrompt.modal();
      promise
        .then((remark) => {
          // 点击确定按钮的回调处理
          if (remark === "") {
            return;
          }
          updateChangeOrderRemark(this.id, { remark: remark }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((r) => {});
    },
    updateTicketNo: function () {
      this.modalTitle = "修改改签票号：";
      const promise = this.$refs.modalPrompt.modal();
      promise
        .then((ticketNo) => {
          // 点击确定按钮的回调处理
          if (ticketNo === "") {
            return;
          }
          updateChangeOrderTicketNo(this.id, { ticketNo }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((r) => {});
    },
    editPrice: function () {
      this.modalTitle = "修改价格";
      this.price1Title = "航司改签费";
      this.price2Title = "我司服务费";
      this.$refs.updateChangeOrderPriceModal
        .modal(this.detail.airChangeCharge, this.detail.serviceCharge)
        .then((v) => this.doUpdatePrice(v))
        .catch(() => {});
    },
    doUpdatePrice: function (v) {
      const params = {
        airChangeCharge: v.price1,
        serviceCharge: v.price2,
      };

      updateChangeOrderPrice(this.id, params, (v) => this.commonShowMessage(v));
    },
    commonShowMessage: function (jsonResult) {
      if (jsonResult.status !== "OK") {
        this.showErrMsg("失败：" + jsonResult.errmsg, "danger");
      } else {
        if (jsonResult.desc !== "") {
          this.showErrMsg(jsonResult.desc);
        } else {
          this.showErrMsg("操作成功");
        }
        this.search();
      }
    },
    showPayType: function (val) {
      return showPayType(val);
    },
    changeTicket: function () {
      let changeTicketNo = this.detail.newTicketNo;
      if (changeTicketNo.length !== 14) {
        changeTicketNo = this.detail.balanceCode + "-" + this.detail.ticketNo;
      }

      //改签时，优先使用detrFlights
      let flights = this.detail.flights;
      if (this.detail.detrFlights.length > 0) {
        flights = this.detail.detrFlights;
      }

      const params = {
        ticketNo: changeTicketNo,
        changeCount: this.detail.changeCount + 1,
        psgName: this.detail.psgName,
        idNo: this.detail.idNo,
        orderId: this.detail.orderId,
        orderNo: this.detail.orderNo,
        parentChangeOrderNo: this.detail.changeOrderNo,
        intlTicket: this.detail.intlTicket,
        oldPnrNo: this.detail.newPnrNo,
        amount: 0,
        cost: 0,
        parvalue: this.detail.parValue,
        tax: this.detail.tax,
        flights: flights,
      };
      console.log(this.detail.flights);
      this.$refs.changeTicketModal
        .modal(params)
        .then((v) => this.doCreateChangeOrder(v))
        .catch((ex) => {});
    },
    doCreateChangeOrder: function (info) {
      createChangeOrder(JSON.stringify(info), (jsonResult) => {
        if (jsonResult.status !== "OK") {
          this.showErrMsg(jsonResult.errmsg, "danger");
        } else {
          this.showErrMsg("创建成功");
          this.$router.replace("/flt/change/order/" + jsonResult.returnCode);
        }
      });
    },
    refundTicket: function () {
      const amount = this.detail.parValue + this.detail.tax;
      const cost = amount;
      //退票时，优先使用detrFlights
      let flights = this.detail.flights;
      if (this.detail.detrFlights.length > 0) {
        flights = this.detail.detrFlights;
      }
      this.$refs.refundTicketModal
        .modal(
          this.detail.newTicketNo,
          this.detail.psgName,
          this.detail.idNo,
          0,
          this.detail.orderNo,
          flights,
          this.detail.intlTicket,
          amount,
          cost,
          this.detail.parValue,
          this.detail.tax
        )
        .then((info) => {
          this.doCreateRefundOrder(info);
        })
        .catch((ex) => {});
    },
    doCreateRefundOrder: function (info) {
      createRefundOrder(JSON.stringify(info), (jsonResult) => {
        if (jsonResult.status !== "OK") {
          this.showErrMsg(jsonResult.errmsg, "danger");
        } else {
          // console.log(jsonResult)
          this.$router.push("/flt/refund/order/" + jsonResult.returnCode);
        }
      });
    },
    rollbackStatus: function () {
      this.modalTitle = "确定将订单回滚吗？请输入理由：";

      this.$refs.modalPrompt
        .modal()
        .then((remark) => {
          rollbackChangeOrderStatus(this.id, { remark }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {
          console.log(ex);
        });
    },
    updateFlightInfo: function (info) {
      //修改改签订单中的航班信息
      console.log(info);
      this.$refs.modalFlightUpdate
        .modal(info.id, info)
        .then((fltInfo) => {
          //执行修改
          fltInfo.orderId = this.id;
          // console.log(fltInfo)
          updateChangeOrderFlightInfo(this.id, fltInfo, (v) => {
            if (v.status !== "OK") {
              this.showErrMsg(jsonResult.errmsg, "danger");
            } else {
              this.showErrMsg("修改成功");
              this.search();
            }
          });
        })
        .catch((ex) => {});
    },
    sendSms: function () {
      this.modalTitle = "请输入接收短信的手机号：";
      this.$refs.modalSms
        .modal(2, this.id, 0)
        .then((v) => {
          const params = {
            orderType: this.orderType,
            orderId: this.id,
            mobileNo: v.mobile,
            smsContent: v.smsContent,
            smsFormat: v.smsFormat,
          };
          sendOrderSmsContent(params, (v) => {
            this.commonShowMessage(v);
          });
        })
        .catch((ex) => {});
    },

    removeAttachment: function (idx) {
      this.attachments.splice(idx, 1);
    },
    editAttachment: function () {
      this.$refs.modalUploadFile.modal().then((v) => {
        this.commonShowMessage(v);
      });
    },
    viewImg: function (imgUrl) {
      console.log(imgUrl);
      this.$refs.modalViewer.modal(imgUrl);
    },
    createOrderChange: function (btn) {
      $(btn).attr("disabled", true);
      createExternalOrderChange(
        this.id,
        (v) => {
          this.commonShowMessage(v);
        },
        () => $(btn).attr("disabled", false)
      );
    },
    syncExternalOrderStatus: function (btn) {
      $(btn).attr("disabled", true);
      syncExternalOrderChangeStatus(
        this.id,
        (v) => {
          this.commonShowMessage(v);
        },
        () => $(btn).attr("disabled", false)
      );
    },
    payForExternalOrder: function () {
      payForExternalOrder(this.id, (v) => {
        this.commonShowMessage(v);
      });
    },
  },
};
// 250
// 957
// 972 2021-11-12
</script>